package com.genuine.nfc;

import java.nio.charset.Charset;

import android.content.Intent;
import android.net.Uri;

public class NFCGlobal {
	public static Intent getNdefIntent(byte[] payLoad) {
		Intent it = null;
		Uri uri = null;
		byte[] domain = new byte[payLoad.length - 1];
		byte type = payLoad[0];
		System.arraycopy(payLoad, 1, domain, 0, domain.length);
		
		if (type == (byte)0x01) {
			uri = Uri.parse("http://www." + new String(domain, Charset.forName("US-ASCII")));
			it = new Intent(Intent.ACTION_VIEW, uri);
		} else if (type == (byte)0x02) {
			uri = Uri.parse("https://www." + new String(domain, Charset.forName("US-ASCII")));
			it = new Intent(Intent.ACTION_VIEW, uri);
		} else if (type == (byte)0x03) {
			uri = Uri.parse("http://" + new String(domain, Charset.forName("US-ASCII")));
			it = new Intent(Intent.ACTION_VIEW, uri);
		} else if (type == (byte)0x04) {
			uri = Uri.parse("https://" + new String(domain, Charset.forName("US-ASCII")));
			it = new Intent(Intent.ACTION_VIEW, uri);
		} else if (type == (byte)0x05) {
			uri = Uri.parse("tel:" + new String(domain, Charset.forName("US-ASCII")));
			it = new Intent(Intent.ACTION_DIAL, uri);
		} else if (type == (byte)0x05) {
			uri = Uri.parse("mailto:" + new String(domain, Charset.forName("US-ASCII")));
			it = new Intent(Intent.ACTION_SENDTO, uri);
		} else {
			return null;
		}
		
		return it;
	}
}
